package com.sandeep;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Servlet1
 */
@WebServlet("/Servlet1")
public class Servlet1 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Servlet1() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();

		String Driver = "com.mysql.jdbc.Driver";
		String connectionURL = "jdbc:mysql://localhost:3306/STUDENTS";
		Connection connection;

		try {

			String firstname = request.getParameter("fName");
			String lastname = request.getParameter("lName");
			String course = request.getParameter("course");
			String Email = request.getParameter("eId");
			long Mob = Long.parseLong(request.getParameter("mob"));

			Class.forName(Driver);

			connection = DriverManager.getConnection(connectionURL, "root",
					"sannu");

			PreparedStatement pst = connection
					.prepareStatement("insert into ONLINEREGISTRATION (fName, lName, course, eId, mob) values(?,?,?,?,?)");
			pst.setString(1, firstname);
			pst.setString(2, lastname);
			pst.setString(3, course);
			pst.setString(4, Email);
			pst.setLong(5, Mob);
			int i = pst.executeUpdate();
			if (i != 0) {
				pw.println("<br>THANKS FOR VERIFICATION");

			} else {
				pw.println("failed to insert the data");
			}
		} catch (Exception e) {
			System.out.println("Exception : " + e.toString());

		}

	}
}